<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>监听模型数据</title>
</head>
<body ng-app="app">
	<div ng-controller="ctrl">
		<form name="myForm">
			<input type="text" ng-model="msg"/><br/>
			<span ng-show="myForm.msg.$error.required">请输入数据！</span>
		</form>
	</div>

	<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.7/angular.js"></script>
	<script>
		let app = angular.module("app", []);
		app.controller("ctrl", ($scope) => {
			$scope.msg = "Hello";
			//监听模型数据
			$scope.$watch("msg", ((newVal, oldVal) => {
				console.log(`${oldVal} changes to ${newVal}`);
			}));
		});
	</script>
</body>
</html>
